package com.park.web.util.excel;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ExcelUtil {
	private static final Logger logger = LoggerFactory.getLogger(ExcelUtil.class);
	private ExcelUtil(){}
	
	public static Sheet readExcel(String excelPath){
		Workbook workbook = null;
		Sheet sheet = null;
		 try {
			 workbook = WorkbookFactory.create(new FileInputStream(new File(excelPath)));
			 sheet = workbook.getSheetAt(workbook.getActiveSheetIndex());
		 } catch (IOException e) {
			 logger.error("读取excel出错",e);
		}finally {
			if(workbook != null){
				try {
					workbook.close();
				} catch (IOException e) {
					 logger.error("关闭流出错",e);
				}
			}
		}
		 return sheet;
	}

}
